package SQL.valueUtil;
import SQL.abysnSQL.Cop;

public class ValueComparator {
	Object right,left;
	public Cop cop;
	
	public void setLeft(String l){
		left = l;
	}
	public void setLeft(Integer l){
		left = l;
	}
	public void setLeft(Float l){
		left = l;
	}
	public void setRight(String r){
		right = r;
	}
	public void setRight(Integer r){
		right = r;
	}
	public void setRight(Float r){
		right = r;
	}
	
	public boolean compare(){
		if(left instanceof Integer){
			int l = (Integer)left;
			if(right instanceof Integer){
				int r = (Integer)right;
				switch(cop.cop){
				case LT: return  l<r;
				case LE: return l<=r;
				case EQ: return l==r;
				case GE: return l>=r;
				case GT: return  l>r;
				case NEQ:return l!=r;
				}
			}
			if(right instanceof Float){
				float r = (Float)right;
				switch(cop.cop){
				case LT: return  l<r;
				case LE: return l<=r;
				case EQ: return l==r;
				case GE: return l>=r;
				case GT: return  l>r;
				case NEQ:return l!=r;
				}
			}
		}
		else if(left instanceof Float){
			float l = (Float)left;
			if(right instanceof Integer){
				int r = (Integer)right;
				switch(cop.cop){
				case LT: return  l<r;
				case LE: return l<=r;
				case EQ: return l==r;
				case GE: return l>=r;
				case GT: return  l>r;
				case NEQ:return l!=r;
				}
			}
			if(right instanceof Float){
				float r = (Float)right;
				switch(cop.cop){
				case LT: return  l<r;
				case LE: return l<=r;
				case EQ: return l==r;
				case GE: return l>=r;
				case GT: return  l>r;
				case NEQ:return l!=r;
				}
			}
		}else {
			String l = (String)left;
			String r = (String)right;
			switch(cop.cop) {
			case EQ: return l.equals(r);
			case NEQ: return !l.equals(r);
			case LT: return l.compareTo(r) < 0;
			case LE: return l.compareTo(r) <= 0;
			case GT: return l.compareTo(r) > 0;
			case GE: return l.compareTo(r) >= 0;
			}
		}
		return false;
	}
}